package com.u2bmvg.main;

import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.ErrorReason;
import com.google.android.youtube.player.YouTubePlayer.OnInitializedListener;
import com.google.android.youtube.player.YouTubePlayer.PlayerStateChangeListener;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;
import com.googlecode.androidannotations.annotations.AfterViews;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.Fullscreen;
import com.googlecode.androidannotations.annotations.NoTitle;
import com.googlecode.androidannotations.annotations.ViewById;


@EActivity(R.layout.activity_main)
@Fullscreen
@NoTitle
public class MainActivity extends YouTubeBaseActivity implements OnInitializedListener, PlayerStateChangeListener {

	public static final String GOOGLE_API_KEY = "AIzaSyDotLE0lBntS80iVZk9G4QfkdEYkX4GkMc";
	
	@ViewById(R.id.youtube_view) YouTubePlayerView youtubeView;
	@ViewById(R.id.gljni_view) GL2JNIView gljniView;

	YouTubePlayer youtubePlayer;

	
	@AfterViews
	void initialize(){
		youtubeView.initialize(GOOGLE_API_KEY, this);
	}
	
	@Override
	public void onInitializationFailure(Provider provider, YouTubeInitializationResult error) {
	}

	@Override
	public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean restored) {
		player.setPlayerStateChangeListener(this);
		player.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
		player.cueVideo("avP5d16wEp0");
		youtubePlayer = player;
	}


	@Override
	public void onAdStarted() {
		// TODO Auto-generated method stub
	}


	@Override
	public void onError(ErrorReason arg0) {
		// TODO Auto-generated method stub
	}


	@Override
	public void onLoaded(String arg0) {
//		youtubePlayer.play();
	}


	@Override
	public void onLoading() {
		// TODO Auto-generated method stub
	}


	@Override
	public void onVideoEnded() {
		// TODO Auto-generated method stub
	}


	@Override
	public void onVideoStarted() {
		// TODO Auto-generated method stub
	}

	@Override
	public void onBackPressed(){
		super.onBackPressed();
	}
	
    @Override protected void onPause() {
        super.onPause();
        gljniView.onPause();
    }

    @Override protected void onResume() {
        super.onResume();
        gljniView.onResume();
    }
}
